import java.util.Arrays;

class Solution {
    public static boolean CheckPermutation1(String s1, String s2) {
        //假设是让s1重新排列后能否变成s2
        if (s1.length() != s2.length()) return false;
        int j = 0;
        for (int i = 0; i < s2.length(); i++) {
            char ch2 = s2.charAt(i);
            for (j = 0; j < s1.length(); j++) {
                char ch1 = s1.charAt(j);
                if (ch1 == ch2) {
                    StringBuilder str = new StringBuilder(s1);
                    str.setCharAt(j, '0');
                    s1 = str.toString();
                    break;
                }
            }
            if (j == s1.length()) return false;
        }
        return true;
    }

    public boolean CheckPermutation2(String s1, String s2) {
        if (s1.length() != s2.length()) {
            return false;
        }
        char[] str1 = s1.toCharArray();
        char[] str2 = s2.toCharArray();
        Arrays.sort(str1);
        Arrays.sort(str2);
        return Arrays.equals(str1, str2);
    }


    public static void main(String[] args) {
        CheckPermutation1("abb", "aab");
    }

    public int lastStoneWeight(int[] stones) {
        int index = stones.length - 1;
        for (int i = 0; i < stones.length - 1; i++) {
            Arrays.sort(stones);
            if (stones[index] == 0) break;
            stones[index] -= stones[index - 1];
            stones[index - 1] = 0;
        }
        return stones[index];
    }
}